package com.yeqiangwei.commons.nimage;

import java.io.File;
import java.io.IOException;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * 
 * @author aroot
 *
 */
public class Image {
	
	private static final Log log = LogFactory.getLog(Image.class);
	
	private File file;
	private java.awt.Image _image;
	private int width;
	private int height;
	
	private Image(File file) throws IOException {
		this.file = file;
		this._image = javax.imageio.ImageIO.read(file);
		this.width = this._image.getWidth(null);
		this.height = this._image.getHeight(null);
	}
	
	public static final Image read(File file) {
		if(!file.exists()) {
			return null;
		}
		try {
			return new Image(file);
		} catch (IOException e) {
			log.error(e);
		}
		return null;
	}

	public File getFile() {
		return file;
	}

	public int getWidth() {
		return width;
	}

	public int getHeight() {
		return height;
	}
}
